import copy from './copy.js'

export default function myExample() {
    return {
        name: 'my-example', // this name will show up in warnings and errors
        resolveId(source) {
            //   console.log('source',source)
            if (source === 'virtual-module') {
                return source; // this signals that rollup should not ask other plugins or check the file system to find this id
            }
            return null; // other ids should be handled as usually
        },
        load(id) {
            //   console.log('id', id)
            if (id === 'virtual-module') {
                return 'export default "This is virtual!"'; // the source code for "virtual-module"
            }
            return null; // other ids should be handled as usually
        },
        transform(code, id) {

            if (code.indexOf('import.meta.glob') != -1) {
                // 获取路径
                let from = code.match(/import.meta.glob\('(\S*)'/)[1];
                const url = from
                from = from.replace('@', 'src')
                from = from.split('/')
                const file = from.pop()
                from = from.join('/')
                code = code.replace(url, `./assets/${file}`)
                console.log(from)
                copy(from, 'components_dist/assets')
            }
            return code
            // if (!keys.length) return null;
            // if (!filter(id)) return null;
            // return executeReplacement(code, id);
        }
    };
}